package com.xqc.rabbit;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
* @author 作者 Gavin.Dai/SNSSZ00036
* @dateTime 创建时间：2020年8月11日 下午1:09:35
* @version V1.0.0
* 类说明
*/
public class ConnectionUtils {
	
	private ConnectionUtils(){}

	private static final String HOST = "localhost";
	private static final int PORT =5672;
	private static final String USER_NAME = "guest";
	private static final String PASS_WORD = "guest";
	private static final String V_HOST = "/";
	
	/**
	 * 通过连接工厂获取连接
	 */
	public static Connection getConn() throws IOException, TimeoutException{
		//1、定义连接工厂
		ConnectionFactory factory = new ConnectionFactory();
		//2、设置服务器地址
		factory.setHost(HOST);
		//3.设置端口
		factory.setPort(PORT);
		//4、设置虚拟主机、用户名、密码
		factory.setVirtualHost(V_HOST);
		factory.setUsername(USER_NAME);
		factory.setPassword(PASS_WORD);
		return factory.newConnection();
	}
}
